package com.mz.ozy.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.recyclerview.widget.RecyclerView;

import com.mz.ozy.R;
import com.mz.ozy.activity.home.CitySelectActivity;
import com.mz.ozy.bean.DbBean;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class CityAdapter extends RecyclerView.Adapter<CityAdapter.MyViewHolder> {



    private Context mContext;
    List<DbBean> cityList;

    public CityAdapter(Context context, List<DbBean> cityList) {
        this.mContext = context;
        this.cityList = cityList;

    }


    public List<DbBean> getCityList() {
        return cityList;
    }

    public void setCityList(List<DbBean> cityList) {
        this.cityList = cityList;
    }

    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new MyViewHolder(LayoutInflater.from(mContext).inflate(R.layout.item_city, parent, false));
    }

    @Override
    public void onBindViewHolder(MyViewHolder holder, final int position) {
        DbBean dbBean = cityList.get(position);
        holder.mCityTv.setText(dbBean.getAreaName());
        holder.mCityTv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(mContext instanceof CitySelectActivity){
                    CitySelectActivity activity  = (CitySelectActivity) mContext;
                    activity.goNearbyBsFragment(cityList.get(position));
                }
            }
        });

    }

    @Override
    public int getItemCount() {
        return cityList.size();
    }


    static class MyViewHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.cityTv)
        TextView mCityTv;
        public MyViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }


}
